package com.ngkj.zmfptback.sys.initData.util;

import com.ngkj.zmfptback.sys.initData.bean.SysArea;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ChenHN
 * @since 2021/11/1 creation
 **/
public class AreaUtils {

    public static Map<String, List<SysArea>> getStringListMap(List<SysArea> allAreas) {
        Map<String,List<SysArea>> map = new HashMap<>(16);
        if (ObjectUtils.isEmpty(allAreas)) {
            return map;
        }
        allAreas.forEach((item)->{
            long parentId = item.getParentId();
            String parentString = Long.toString(parentId);
            if (map.containsKey(parentString)){
                List<SysArea> sysAreaList = map.get(parentString);
                sysAreaList.add(item);
                map.put(parentString,sysAreaList);
            }else{
                List<SysArea> sysAreaList = new ArrayList<>();
                sysAreaList.add(item);
                map.put(parentString,sysAreaList);
            }
        });
        return map;
    }
}
